//全局变量
var myDate=new Date();
var year=myDate.getFullYear();
var month=myDate.getMonth()+1;
var day=myDate.getDate();
var time=year+"年"+month+"月"+day+"日 ";
var tt=[];
//四个表格的全部变量用于去除控制台重复打桩问题
var myChartindex1;
var myChartindex2;
var myChartindex3;
var myChartindex4;
//页面以加载就显示四个图表区域和四个表格
$(document).ready(function(){
	//显示四个表格
	getTables();
});   


	//1获取应用数（今日应用数和总应用数）
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getAppAmount",
		"dataType":"json",
		"type":"post",
		"success":function(obj){
			if(obj!=null){
				var todayApp=obj[0];
				var allApp=obj[1];
				$("#todayApp").html(todayApp);
				$("#allApp").html(allApp);
				if(todayApp==0){
					$("#todayApp").html(0);
				}else{
					$("#todayApp").numberRock({
					    speed:4,
					    count:todayApp,
						});
				}
				if(allApp==0){
					$("#allApp").html(0);
				}else{
					$("#allApp").numberRock({
					    speed:4,
					    count:allApp,
						});
				}
			}
		}
	});
	//2获取主题队列数（今日新增主题队列数和总主题队列）
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getToppicAmount",
		"dataType":"json",
		"type":"post",
		"success":function(obj){
			if(obj!=null){
				var todayTopic=obj[0];
				var allTopic=obj[1];
				$("#todayTopic").html(todayTopic);
				$("#allTopic").html(allTopic);
				if(todayTopic==0){
					$("#todayTopic").html(0);
				}else{
					$("#todayTopic").numberRock({
					    speed:4,
					    count:todayTopic,
						});
				}
				if(allTopic==0){
					$("#allTopic").html(0);
				}else{
					$("#allTopic").numberRock({
					    speed:4,
					    count:allTopic,
						});
				}
			}
		}
	});
	//3获取消息流量（今日新增消息流量和总消息流量）
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getMessageAmount",
		"dataType":"json",
		"type":"post",
		"success":function(obj){
			if(obj!=null){
				var todayMessage=obj[0];
				var allMessage=obj[1];
				if(todayMessage>=1000000000000){
					$("#todayMessage").html((todayMessage/1000000000000).toFixed(1)+'万亿');
				}else if(todayMessage>=100000000&&todayMessage<1000000000000){
					$("#todayMessage").html((todayMessage/100000000).toFixed(1)+'亿');
				}else if(todayMessage>=10000&&todayMessage<100000000){
					$("#todayMessage").html((todayMessage/10000).toFixed(2)+'万');
				}else{
					$("#todayMessage").html(todayMessage);
				}
				if(allMessage>=1000000000000){
					$("#allMessage").html((allMessage/1000000000000).toFixed(1)+'万亿');
				}else if(allMessage>=100000000&&allMessage<1000000000000){
					$("#allMessage").html((allMessage/100000000).toFixed(1)+'亿');
				}else if(allMessage>=10000&&allMessage<100000000){
					$("#allMessage").html((allMessage/10000).toFixed(2)+'万');
				}else{
					$("#allMessage").html(allMessage);
				}
				if(todayMessage==0){
					$("#todayMessage").html(0);
				}else{
					$("#todayMessage").numberRock({
					    speed:4,
					    count:todayMessage,
						});
				}
				if(allMessage==0){
					$("#allMessage").html(0);
				}else{
					$("#allMessage").numberRock({
					    speed:4,
					    count:allMessage,
						});
				}
			}
		}
	});
	//4获取消息发送平均延迟
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getAvgDelay",
		"dataType":"json",
		"type":"POST",
		"success":function(obj){
			if(obj!=null){
				var allDelay=obj[0];
				var allMessage=obj[1];
				
				if(allDelay==0){
					$("#avgDelay").html(0);
				}else{
					$("#avgDelay").html(allDelay);
				}
			}
		}
	});

/******************定时刷新***********************************/
function getPageData(){
	//1获取应用数（今日应用数和总应用数）
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getAppAmount",
		"dataType":"json",
		"type":"post",
		"success":function(obj){
			if(obj!=null){
				var todayApp=obj[0];
				var allApp=obj[1];
				$("#todayApp").html(todayApp);
				$("#allApp").html(allApp);
				if(todayApp==0){
					$("#todayApp").html(0);
				}else{
					$("#todayApp").numberRock({
					    speed:4,
					    count:todayApp,
						});
				}
				if(allApp==0){
					$("#allApp").html(0);
				}else{
					$("#allApp").numberRock({
					    speed:4,
					    count:allApp,
						});
				}
			}
		}
	});
	//2获取主题队列数（今日新增主题队列数和总主题队列）
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getToppicAmount",
		"dataType":"json",
		"type":"post",
		"success":function(obj){
			if(obj!=null){
				var todayTopic=obj[0];
				var allTopic=obj[1];
				$("#todayTopic").html(todayTopic);
				$("#allTopic").html(allTopic);
				if(todayTopic==0){
					$("#todayTopic").html(0);
				}else{
					$("#todayTopic").numberRock({
					    speed:4,
					    count:todayTopic,
						});
				}
				if(allTopic==0){
					$("#allTopic").html(0);
				}else{
					$("#allTopic").numberRock({
					    speed:4,
					    count:allTopic,
						});
				}
			}
		}
	});
	//3获取消息流量（今日新增消息流量和总消息流量）
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getMessageAmount",
		"dataType":"json",
		"type":"post",
		"success":function(obj){
			if(obj!=null){
				var todayMessage=obj[0];
				var allMessage=obj[1];
				if(todayMessage>=1000000000000){
					$("#todayMessage").html((todayMessage/1000000000000).toFixed(1)+'万亿');
				}else if(todayMessage>=100000000&&todayMessage<1000000000000){
					$("#todayMessage").html((todayMessage/100000000).toFixed(1)+'亿');
				}else if(todayMessage>=10000&&todayMessage<100000000){
					$("#todayMessage").html((todayMessage/10000).toFixed(2)+'万');
				}else{
					$("#todayMessage").html(todayMessage);
				}
				if(allMessage>=1000000000000){
					$("#allMessage").html((allMessage/1000000000000).toFixed(1)+'万亿');
				}else if(allMessage>=100000000&&allMessage<1000000000000){
					$("#allMessage").html((allMessage/100000000).toFixed(1)+'亿');
				}else if(allMessage>=10000&&allMessage<100000000){
					$("#allMessage").html((allMessage/10000).toFixed(2)+'万');
				}else{
					$("#allMessage").html(allMessage);
				}
				if(todayMessage==0){
					$("#todayMessage").html(0);
				}else{
					$("#todayMessage").numberRock({
					    speed:4,
					    count:todayMessage,
						});
				}
				if(allMessage==0){
					$("#allMessage").html(0);
				}else{
					$("#allMessage").numberRock({
					    speed:4,
					    count:allMessage,
						});
				}
			}
		}
	});
	//4获取消息发送平均延迟
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getAvgDelay",
		"dataType":"json",
		"type":"POST",
		"success":function(obj){
			if(obj!=null){
				var allDelay=obj[0];
				var allMessage=obj[1];
				
				if(allDelay==0){
					$("#avgDelay").html(0);
				}else{
					$("#avgDelay").html(allDelay);
				}
			}
		}
	});
}
/******************定时刷新结束******************************/
//显示四个表格的ajax
function getTables(){
//第一个表格：获取主页实时消息流量图表
$.ajax({
	"url":"/zhgl-jzstyxx-manage/index/getMessageByNowTime",
	"dataType":"json",
	"type":"post",
	"success":function(obj){
		if(obj!=null){
			var keys=obj[0];
			var values=obj[1];
		}
		getMessageByNowTime(keys,values);
	}
});
//第二个表格：获取实时消息发送延迟
$.ajax({
	"url":"/zhgl-jzstyxx-manage/index/getDelayByNowTime",
	"dataType":"json",
	"type":"post",
	"success":function(obj){
		if(obj!=null){
			hours=obj[0];
			delays=obj[1];
		}
		getDelayByNowTime(hours,delays);
	}
});
//第三个表格：获取内存实时占用情况
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getDataByDate",
		"dataType":"json",
		"type":"post",
		"success":function(obj){
			if(obj!=null){
				var ti=obj[0];//时间
				var nc=obj[1];//值
				for(var i=0;i<nc.length;i++){//把B换为MB
					var n=nc[i]/1024/1024;
					n=n.toFixed(2);
					nc[i]=n;
				}
			}
			getDataByDate(ti,nc);
		}
	});
	

//第四个表格：获取磁盘剩余空间
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/index/getcipan",
		"type":"post",
		"dataType":"json",
		"success":function(obj){
			if(obj!=null){
				var tis=obj[0];//时间
				var cp=obj[1]
				for(var i=0;i<cp.length;i++){
					n=((cp[i]/1024/1024/1024).toFixed(2));//KB换为GB
					cp[i]=n;
				}
			}
			getcipan(tis,cp);
		}
	});
}
//四个图表区域的ajax结束

//四个图表区域的五分钟定时刷新
function getFourTableData(){
		var nowDate=new Date();
		var nowMinute=nowDate.getMinutes();
		var nowSecond=nowDate.getSeconds();
		if(nowMinute%5==0&&nowSecond==0){
			getTables();
		}
}

/*******第一个图表显示*******/
function getMessageByNowTime(keys,values){
	/*var myChartindex1;*/
	if(myChartindex1!=null&&myChartindex1!=""&&myChartindex1!=undefined){
		myChartindex1.dispose();
	}
	myChartindex1 = echarts.init(document.getElementById('fir-table-li-fir'));
	var optionindex1 = {
			//表格背景颜色
			backgroundColor:'#fff',
			//表格标题
			title : {text : time+'消息流量实时情况',/*subtext : '单位:  条', */textStyle:{fontSize:14,color:'#000',},x:5,y:10,},
			//提示框，鼠标悬浮交互时的信息提示
		    tooltip : { 
		    	trigger: 'axis',
		    	formatter:function(a){
		    		return a[0].name+"<br/>"
		    		+a[0].seriesName+":"+a[0].value+"条<br/>"
		    	}
		    },
		    dataZoom : { show : false, start : 0,end : 100 },
		    //x轴设计
		    xAxis : [
		        {
		            type : 'value', scale: true,name : '时间',type : 'category',
		    		boundaryGap : false,
					axisLabel:{show:true,textStyle:{color:'#000',},},
					axisLine:{lineStyle:{color:'#000',},},
					axisTink:{show:false,},
					splitLine:{show:false,},
		            data : keys,
		        },
		    ],
		    yAxis : [
		        {
		            type : 'value',
		            scale: false,
		            name : '单位：条',
		            minInterval:100,
		           /* boundaryGap: [0.2, 0.2],*/
					axisLabel:{formatter:'{value}',textStyle:{color:'#000',},},
					axisLine:{lineStyle:{color:'#000',},},
					axisTick:{show:false,},
					splitLine:{show:false,},
		        },
		    ],
		    series : [
		        {
		            name:'消息流量',
		            type:'line',
					/*smooth : true,//曲线连接
*/					lineStyle:{normal:{color:"#57BA8E",width:2,},},
		            areaStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0,color: '#57BA8E' }, {offset: 1, color: 'rgba(0,0,0,0)' }]), }},
		            data:values,
		            }
		    ]
	}
	myChartindex1.setOption(optionindex1);
}
/*******第二个图表显示*******/
function getDelayByNowTime(hours,delays){
	if(myChartindex2!=null&&myChartindex2!=""&&myChartindex2!=undefined){
		myChartindex2.dispose();
	}
    myChartindex2=echarts.init(document.getElementById('fir-table-li-sec'));
	//自定义表格配置项
	var optionindex2 = {
			//表格背景颜色
			backgroundColor:'#fff',
			//标题样式
		    title : {
		        text: time+'消息发送延迟实时情况',
		        /*subtext: '延迟时间 m',*/
				textStyle:{
					fontSize:14,
					color:'#000',
				},
				subtextStyle:{
					fontSize:12,
					color:'#000',
				},
				x:5,
				y:10,
		    },
			//提示框，鼠标悬浮交互时的信息提示
		    tooltip : {
		        trigger: 'axis',
		    	formatter:function(a){
		    		return a[0].name+"<br/>"
		    		+a[0].seriesName+":"+a[0].value+"毫秒<br/>"
		    	}
		    },
/*			 //图例
		    legend: {
		        data:['延迟','总数']
		    },*/
			 //是否启用拖拽重计算特性
		    calculable : true,
		    //X轴设计
		    xAxis : [
		        {
		        	type : 'value', scale: true,name : '时间',type : 'category',
			    	boundaryGap : false,
					axisLabel:{show:true,textStyle:{color:'#000',},},
					axisLine:{lineStyle:{color:'#000',},},
					axisTink:{show:false,},
					splitLine:{show:false,},
		            data :hours
		        }
		    ],
		    //Y轴设计
		    yAxis : [
		        {
		            type : 'value',
		            scale:true,
		            min:0,
		            minInterval:100,
		            name:'单位: 毫秒',
					axisLabel:{
						formatter:'{value}',
						textStyle:{
							color:'#000',
						},
					},
					axisLine:{
						/*symbol:['none','arrow'],*/ //箭头
						lineStyle:{
							color:'#000',
						},
					},
					axisTick:{
						show:false,
					},
					splitLine:{
						show:false,
					},
		        }
		    ],
		    series : [
		        {
		            name:'延迟毫秒',
		            type:'line',
		            data:delays,
		            areaStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0,color: '#7D83FF' }, {offset: 1, color: 'rgba(0,0,0,0)' }]), }},
		            barWidth:30,
		            itemStyle:{
		            	emphasis:{
		            		barBorderRadius:30,
		            	},
		            	normal:{
		            		barBorderRadius:[20,20,0,0],
		            		color:'#7D83FF',
		            	},
		            },
		        },
		    ]
		};
	//使用指定上午配置型和数据显示图表
	myChartindex2.setOption(optionindex2);
}
/*******第三个图表显示*******/
function getDataByDate(ti,nc){
	if(myChartindex3!=null&&myChartindex3!=""&&myChartindex3!=undefined){
		myChartindex3.dispose();
	}
    myChartindex3 = echarts.init(document.getElementById('sec-table-li-fir'));
	var optionindex3 = {
			//表格背景颜色
			backgroundColor:'#fff',
			//表格标题
			title : {text : time+'消息内存实时占用情况',/*subtext : '单位:  条', */textStyle:{fontSize:14,color:'#000',},x:5,y:10,},
			//提示框，鼠标悬浮交互时的信息提示
		    tooltip : { trigger: 'axis',
		    	formatter:function(a){
		    		return a[0].name+"<br/>"
		    		+a[0].seriesName+":"+a[0].value+"MB<br/>"
		    	}
			},
/*		    legend:{
		    	data:[{
		    		name:'内存实时占用',
		    		icon:'emptyCircle',
		    		textStyle:{fontWeight:'bold',color:'#67479A'}
		    	}
		    	,{
		    		name:'预警阈值',
		    		icon:'emptyCircle',
		    		textStyle:{fontWeight:'bold',color:'red'}
		    	}],
		    	y:30,
		    },*/
		    dataZoom : { show : false, start : 0,end : 100 },
		    //x轴设计
		    xAxis : [
		        {
		        	type : 'value', scale: true,name : '时间',type : 'category',
			    	boundaryGap : false,
					axisLabel:{show:true,textStyle:{color:'#000',},},
					axisLine:{lineStyle:{color:'#000',},},
					axisTink:{show:false,},
					splitLine:{show:false,},
		            data : ti,
		            nameTextStyle:{color:'#000',},
		        },
		    ],
		    yAxis : [
		        {
		        	type : 'value',
		            name:'单位: MB',
					axisLabel:{
						formatter:'{value}',
						textStyle:{
							color:'#000',
						},
					},
					axisLine:{
						lineStyle:{
							color:'#000',
						},
					},
					axisTick:{
						show:false,
					},
					splitLine:{
						show:false,
					},
		        },
		    ],
		    series : [
		        {
		            name:'内存实时占用',
		            type:'line',
					/*smooth : true,//曲线连接
*/					lineStyle:{normal:{color:"#6E48AD",width:2,},},
		            areaStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0,color: '#6E48AD' }, {offset: 1, color: 'rgba(0,0,0,0)' }]), }},
		            data:nc,
		            },
/*		        {
			        name:'预警阈值',
			        type:'line',
			        lineStyle:{normal:{color:"red",width:1,},},
			        data:[0.6,0.6,0.6,0.6,0.6,0.6,0.6],
			        },*/
		            
		    ]
	}
	myChartindex3.setOption(optionindex3);
}
/*******第四个图表显示*******/
function getcipan(tis,cp){
	if(myChartindex4!=null&&myChartindex4!=""&&myChartindex4!=undefined){
		myChartindex4.dispose();
	}
	myChartindex4=echarts.init(document.getElementById('sec-table-li-sec'));
	//自定义表格配置项
	var optionindex4 = {
			//表格背景颜色
			backgroundColor:'#fff',
			//标题样式
		    title : {
		        text: time+'磁盘剩余空间实时情况',
		        /*subtext: '延迟时间 m',*/
				textStyle:{
					fontSize:14,
					color:'#000',
				},
				subtextStyle:{
					fontSize:12,
					color:'#000',
				},
				x:5,
				y:10,
		    },
			//提示框，鼠标悬浮交互时的信息提示
		    tooltip : {
		        trigger: 'axis',
		    	formatter:function(a){
		    		return a[0].name+"<br/>"
		    		+a[0].seriesName+":"+a[0].value+"GB<br/>"
		    	}
		    },
/*			 //图例
		    legend: {
		        data:['延迟','总数']
		    },*/
			 //是否启用拖拽重计算特性
		    calculable : true,
		    //X轴设计
		    xAxis : [
		        {
		        	type : 'value', scale: true,name : '时间',type : 'category',
			    	boundaryGap : false,
					axisLabel:{show:true,textStyle:{color:'#000',},},
					axisLine:{lineStyle:{color:'#000',},},
					axisTink:{show:false,},
					splitLine:{show:false,},
		            data :tis
		        }
		    ],
		    //Y轴设计
		    yAxis : [
		        {
		        	type : 'value',
		            name:'单位: GB',
					axisLabel:{
						formatter:'{value}',
						textStyle:{
							color:'#000',
						},
					},
					axisLine:{
						lineStyle:{
							color:'#000',
						},
					},
					axisTick:{
						show:false,
					},
					splitLine:{
						show:false,
					},
		        }
		    ],
		    series : [
		        {
		            name:'磁盘剩余空间',
		            type:'line',
		            data:cp,
		            barWidth:30,
		            areaStyle: {normal: {color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0,color: '#ff6a6a' }, {offset: 1, color: 'rgba(125,125,125,0)' }]), }},
		            itemStyle:{
		            	emphasis:{
		            		barBorderRadius:30,
		            	},
		            	normal:{
		            		barBorderRadius:[20,20,0,0],
		            		color:'#ff6a6a',
		            	},
		            },
		            markPoint : {
		            	itemStyle:{
		            		show:true,
		            		color:'#333',
		            	},
		            },

		        },
		    ]
		};
	//使用指定上午配置型和数据显示图表
	myChartindex4.setOption(optionindex4);
}

